package genetic.q1;

import java.util.Arrays;

import genetic.Genotype;

public class TSPGenotype implements Genotype{

	int[] rep;
	TSPGraph graph;

	public TSPGenotype(int[] rep, TSPGraph g){
		this.rep = rep;
		this.graph = g;
	}

	@Override
	public Genotype clone(){
		return new TSPGenotype(Arrays.copyOf(rep, rep.length), graph);
	}

	@Override
	public int[] getIntString() {
		return rep;
	}



	@Override
	public String toString() {
		int length = graph.getDistance(rep[0]-1, rep[rep.length-1]-1);
		for (int i=0; i<rep.length-1; i++){
			length = length + graph.getDistance(rep[i]-1, rep[i+1]-1);
		}
		return "Distance " + length + ": " + Arrays.toString(rep);
	}

}
